<%--
  Created by IntelliJ IDEA.
  User: FENG1
  Date: 2022-05-24
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>选择商品加入订单</title>
    <link href="static/component/pear/css/pear.css" rel="stylesheet" />
    <style>
        .main-container1{
            text-align: center;
            font-weight: bolder;
            font-size: 28px;
            font-family: '楷体', '微软雅黑';
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container1">
            最多可购买<span>${goods.goodsQuantity}${goods.specifiCations}</span>
        </div>
        <div class="main-container">
            <div class="layui-form-item">
                <input type="hidden" name="goodsId" value="${goods.goodsId}">
                <label class="layui-form-label">商品名称</label>
                <div class="layui-input-block">
                    <input type="text" name="goodsName"  required value="${goods.goodsName}" disabled="disabled"  class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品价格</label>
                <div class="layui-input-block">
                    <input type="text" name="goodsPrice" value="${goods.goodsPrice}"  disabled="disabled" class="layui-input">
                </div>
            </div>
<%--            <div class="layui-form-item">
                <label class="layui-form-label">商品单位</label>
                <div class="layui-input-block">
                    <input type="text" value="${goods.specifiCations}"  disabled="disabled" class="layui-input">
                </div>
            </div>--%>
            <div class="layui-form-item">
                <label class="layui-form-label">购买数量</label>
                <div class="layui-input-block">
                    <input type="text" name="goodsCount" value="1" id="goodsCount" lay-verify="number"  placeholder="请输入购买数量"  class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-danger JrOrder" lay-submit="" lay-filter="Order-save">
                <i class="layui-icon layui-icon-ok"></i>
                加入购物单
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="static/component/layui/layui.js"></script>
<script src="static/component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        var goodsCount = ${goods.goodsQuantity};
        if(goodsCount<1){
            $('.JrOrder').addClass("layui-btn-disabled").attr("disabled",true);
            layer.msg("该商品没有更多库存了",{icon:2,time:1000})
        }else{
            $('.JrOrder').removeClass("layui-btn-disabled").attr("disabled",false);
        }
        //商品数量的校验
        $('#goodsCount').bind('input propertychange', function() {
                if($(this).val()>goodsCount || $(this).val()<1){
                    $('.JrOrder').addClass("layui-btn-disabled").attr("disabled",true);
                }else{
                    $('.JrOrder').removeClass("layui-btn-disabled").attr("disabled",false);
                }
        });
        form.on('submit(Order-save)', function(data){
/*            let goodsCount = $("#goodsCount").val();
            if(goodsCount>${goods.goodsQuantity}){
                layer.msg("没有更多货物！",{icon:2,time:1000});
                return false;
            }*/
            //添加至购物单
            $.post("/retail/addRetailOrder",data.field,function (result) {
                if(result.success){
                    layer.msg(result.msg,{icon:1,time:1000},function (){
                        window.close();
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("OrdersTableId");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            })
        });
    })
</script>
</body>
</html>